﻿// Jinx AJAX Framework
// Copyright (C) 2008 Blake Hegerle
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NUnit.Framework;

using Core;

namespace Formality.TestFramework
{
    [TestFixture]
    public class AddProductionMethods
    {
        [Test]
        public void GenerateMethods()
        {
            for (var i = 1; i < 20; i++)
            {
                var Seq = Make(i);

                Console.Write("public Production add<");

                var Types = (from t in Seq select "R" + t).Join(", ");

                Console.Write(Types);

                Console.Write(">(");

                Console.Write((from t in Seq select string.Format("Symbol<R{0}> r{0}", t)).Join(", "));

                Console.Write(", Func<");

                Console.WriteLine(Types + ", S> SemanticFunc)");

                Console.Write("{ return add(new Production { Head = this, SemanticFunc = SemanticFunc, Symbols = new Symbol[] { ");

                Console.Write((from t in Seq select "r" + t).Join(", "));

                Console.WriteLine(" } }); }");

                //           public Production add<R1, R2>(Symbol<R1> r1, Symbol<R2> r2, Func<R1, R2, S> SemanticFunc)
                // { return add(new Production { Head = this, SemanticFunc = SemanticFunc, Symbols = new Symbol[] { r1, r2 } }); }

            }
        }

        [Test]
        public void GenerateFuncs()
        {
            for (var i = 5; i < 20; i++)
            {
                var Seq = Make(i);

                Console.Write("public delegate TResult Func<");

                Console.Write((from t in Seq select "T" + t).Join(", "));

                Console.Write(", TResult>(");

                Console.Write((from t in Seq select string.Format("T{0} a{0}", t)).Join(", "));

                Console.WriteLine(");");
            }
        }

        private IEnumerable<int> Make(int Count)
        {
            for (var i = 0; i < Count; i++)
                yield return i + 1;
        }
    }
}
